/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package otcapp;

import de.javasoft.plaf.synthetica.SyntheticaSimple2DLookAndFeel;
import java.text.ParseException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import otcapp.controlador.ControladorPrincipal;
import otcapp.controlador.seguridadDecoradores.ControladorPrincipalSeguridad;
import otcapp.controlador.seguridadDecoradores.FabricaContrladores;
import otcapp.seguridad.Permiso;
import otcapp.seguridad.Usuario;
import persistencia.Conexion;
import persistencia.exceptions.ExcepcionFachada;
import persistencia.Fachada;

/**
 *
 * @author diego
 */
public class OtcApp {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        System.out.println(""
                + "\n**************************"
                + "\nOTCapp iniciado Iniciando Conexion"
                + "\n**************************");
        Conexion.getInstancia().crearEntitiManagerFactory("otcAppPU");

//        try {
//            for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
//                if ("Nimbus".equals(info.getName())) {
//                    UIManager.setLookAndFeel(info.getClassName());
//                    break;
//                }
//            }
//        } catch (Exception e) {
//            System.out.println("Nimbus look and feel no esta instalado.");
//        }
        try {
            UIManager.setLookAndFeel(new SyntheticaSimple2DLookAndFeel());
            eliminarHiloLookandFeelSynthetica();
        } catch (ParseException | UnsupportedLookAndFeelException ex) {
            Logger.getLogger(OtcApp.class.getName()).log(Level.SEVERE, null, ex);
        }

        //ControladorPrincipal.getInstancia().iniciar();
        
        FabricaContrladores.getInstancia().getControlador(FabricaContrladores.controlador.PRINCIPAL).iniciar();
    }

    private static void eliminarHiloLookandFeelSynthetica() {
        ThreadGroup rootGroup = Thread.currentThread().getThreadGroup();
        ThreadGroup parentGroup;
        while ((parentGroup = rootGroup.getParent()) != null) {
            rootGroup = parentGroup;
        }

        Thread[] threads = new Thread[rootGroup.activeCount()];
        while (rootGroup.enumerate(threads, true) == threads.length) {
            threads = new Thread[threads.length * 2];
        }

        for (Thread thread : threads) {
            if (thread.getClass().toString().contains("SyntheticaLookAndFeel")) {
                thread.stop();
                break;
            }
        }
    }
}
